﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;

using KeMei.Common;

public partial class ApplicationCase_ApplicationCaseList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ProductDataBind();
        }
    }

    /// <summary>
    /// 取得资料地址
    /// </summary>
    /// <param name="source"></param>
    /// <returns></returns>
    protected string GetFileUrl(string source)
    {
        if (string.IsNullOrEmpty(source))
        {
            return ConfigHelper.SystemUrl + "Style/img/noimages.jpg";
        }
        return ConfigHelper.SystemUrl + source;
    }

    public DataTable GetDataTable
    {
        get
        {
            return ViewState["Table"] == null ? null : ViewState["Table"] as DataTable;
        }
        set
        {
            ViewState["Table"] = value;
        }
    }

    /// <summary>
    /// 绑定产品
    /// yd 2012-05-19
    /// </summary>
    private void ProductDataBind()
    {
        string strId = Request["Id"];

        int id = 0;
        if (!string.IsNullOrEmpty(strId))
        {
            try
            {
                id = Convert.ToInt32(strId);
            }
            catch (FormatException ex)
            {
                MessageBox.Show(this, ex.Message);
            }
        }
        KeMei.BLL.Syslm bll = new KeMei.BLL.Syslm();
        KeMei.Model.Syslm info = bll.GetModel(id);
        if (info != null)
        {
            lbProductTypeName.Text = "> " + info.TName;
        }

        //根据类别查询产品
        if (strId != null)
        {
            if (!string.IsNullOrEmpty(strId))
            {
                KeMei.BLL.ProductAndCase productBll = new KeMei.BLL.ProductAndCase();
                try
                {
                    DataSet ds = productBll.GetList(" lmID =" + strId + "  order by Taxis desc");
                    DataTable dt = ds.Tables[0];
                    //总数
                    AspNetPager.RecordCount = dt.Rows.Count;

                    GetDataTable = DataTableHelper.GetPagedTable(dt, AspNetPager.CurrentPageIndex, AspNetPager.PageSize);
                    if (GetDataTable.Rows.Count > 0)
                    {
                        repProduct.DataSource = GetDataTable;
                        repProduct.DataBind();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.Message);
                }
            }
        }
        //查询所有产品
        else
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(" lmID In(Select Id From SysLm Where ParentId=2)  order by Taxis desc");

            KeMei.BLL.ProductAndCase productBll = new KeMei.BLL.ProductAndCase();
            try
            {
                DataSet ds = productBll.GetList(sb.ToString());
                DataTable dt = ds.Tables[0];
                //总数
                AspNetPager.RecordCount = dt.Rows.Count;

                GetDataTable = DataTableHelper.GetPagedTable(dt, AspNetPager.CurrentPageIndex, AspNetPager.PageSize);
                if (GetDataTable.Rows.Count > 0)
                {
                    repProduct.DataSource = GetDataTable;
                    repProduct.DataBind();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message);
            }
        }
    }

    protected void AspNetPager_PageChanged(object src, EventArgs e)
    {
        ProductDataBind();
    }
}